<template>
	
	<view>
		
		<!--搜索组件-->
		<view class="search-box">
			<my-search @click="gotoSearch()"></my-search>
		</view>
		
		
		<!--轮播图区域-->
		<view>
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
				<swiper-item v-for="(item,index) in swiperList" :key="index">
					<navigator class="swiper-item" :url="'/subpkg/goods_list/goods_list?goods_id='+item.goods_id">
						<image :src="item.image_src"></image>
					</navigator>
				</swiper-item>
			</swiper>
		</view>
		
		<!--导栏行区域-->
		<view class="nav-list">
			<navigator class="nav-item" v-for="(item,index) in navList" :key="index">
				<image :src="item.image_src" class="nav-img"></image>
			</navigator>
		</view>
		
		<!--楼层区域-->
		<view class="floor-list">
			<view class="floor-item" v-for="(item,index) in floorList" :key="index">
				
				<!--标题-->
				<image :src="item.floor_title.image_src" class="floor-title"></image>
				
				<!--图片区域-->
				<view class="floor-image-box">
					
					<!--左边图片区域-->
					<navigator class="left-image-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src" 
						:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					
					<!--右边图片区域-->
					<view class="right-image-box">
						<navigator class="right-img-item" v-for="(item2,index2) in item.product_list" 
						v-if="index2 != 0" :url="item2.url">
							<image :src="item2.image_src"
							:style="{width:item2.image_width+'rpx'}" mode="widthFix"
							></image>
						</navigator>
					</view>
					
					
				</view>
			</view>
		</view>
		
	
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				//轮播图信息
				swiperList:[],
				//导栏行信息
				navList:[],
				//楼层信息
				floorList:[]
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods:{
			//获取轮播图信息
			async getSwiperList(){
				const res =  await uni.$http.get('/api/public/v1/home/swiperdata')
				if(res.statusCode != 200){
					return uni.showMsg()
				}
				this.swiperList = res.data.message
				console.log(res)
	
			},
			//获取导栏行信息
			async getNavList(){
				const res =  await uni.$http.get('/api/public/v1/home/catitems')
				if(res.statusCode != 200){
					return uni.showMsg()
				}
				this.navList = res.data.message
				console.log(res)
	
			},
			//获取导楼层信息
			async getFloorList(){
				const res =  await uni.$http.get('/api/public/v1/home/floordata')
				if(res.statusCode != 200){
					return uni.showMsg()
				}
				
				//处理一下数据
				res.data.message.forEach((item)=>{
					item.product_list.forEach((img)=>{
						img.url = '/subpkg/goods_list/goods_list?'+img.navigator_url.split("?")[1]
					})
				})
				
				this.floorList = res.data.message
				console.log(res)
	
			},
			//去search页面
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
			
		},
	}
</script>

<style lang="scss">
swiper {
	height: 330rpx;
}
image,.swiper-item{
	height: 100%;
	width: 100%;
}

.nav-list{
	display: flex;
	justify-content: space-around;
	margin: 15rpx 0rpx;
	
}
.nav-img{
	width: 128rpx;
	height: 140rpx;
}

.floor-title{
	height: 66rpx;
	width: 100%;
}

.floor-image-box{
	display: flex;
}

.left-image-box{
	padding-left: 10rpx;
}

.right-image-box{
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
	

}


.search-box{
	position: sticky;
	top: 0;
	z-index: 999;
}
</style>
